package com.campuscarbooking.api.dto;

import com.campuscarbooking.api.model.BusSchedule;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalTime;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BusScheduleDTO {
    private Long id;
    private String routeDirection;
    private String departureTime;
    private String arrivalTime;
    private BigDecimal price;
    private Integer capacity;
    private Integer availableSeats;
    private String status;
    private Boolean isFixed;
    private DriverDTO driver;
    private Double departureLatitude;
    private Double departureLongitude;
    private Double arrivalLatitude;
    private Double arrivalLongitude;

    public static BusScheduleDTO fromEntity(BusSchedule schedule, Integer reservedSeats, DriverDTO driver) {
        if (schedule == null) {
            return null;
        }

        BusScheduleDTO dto = new BusScheduleDTO();
        dto.setId(schedule.getId());
        dto.setRouteDirection(schedule.getRouteDirection().name());
        dto.setDepartureTime(schedule.getDepartureTime().toString());
        dto.setArrivalTime(schedule.getArrivalTime().toString());
        dto.setPrice(schedule.getPrice());
        dto.setCapacity(schedule.getCapacity());
        dto.setDepartureLatitude(schedule.getDepartureLatitude());
        dto.setDepartureLongitude(schedule.getDepartureLongitude());
        dto.setArrivalLatitude(schedule.getArrivalLatitude());
        dto.setArrivalLongitude(schedule.getArrivalLongitude());

        if (reservedSeats != null) {
            dto.setAvailableSeats(schedule.getCapacity() - reservedSeats);
        }

        dto.setStatus(schedule.getStatus().name());
        dto.setIsFixed(schedule.getIsFixed());
        dto.setDriver(driver);

        return dto;
    }

    public static BusScheduleDTO fromEntity(BusSchedule schedule, Integer reservedSeats) {
        return fromEntity(schedule, reservedSeats, null);
    }

    public static BusScheduleDTO fromEntity(BusSchedule schedule) {
        return fromEntity(schedule, null, null);
    }
} 